import { defineStore } from "pinia";
import {ref} from "vue";
import {getLoginUserUsingGet} from "@/api/userController.ts";

export const useLoginUserStore = defineStore("loginUser", () => {
    const loginUser = ref<API.LoginUserVO>({
    userName: "未登录",
  });

  function getLoginUser() {
    return loginUser.value;
  }

    async function fetchLoginUser() {
        const res = await getLoginUserUsingGet();
        if (res.code === 0 && res.data) {
            setLoginUser(res.data);
        }
    }

    function setLoginUser(user: any) {
    loginUser.value = user;
  }

  return {
    getLoginUser,
    setLoginUser,
      fetchLoginUser
  };
});
